package ${package.Controller};

import org.flowers.unbeaten.base.entity.BaseEntity;
import ${package.Entity}.${entity};
import ${package.Service}.${table.serviceName};
import org.flowers.unbeaten.util.DataResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;


/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
@RestController
@RequestMapping("/${lowerEntityName}/${lowerEntityName}")
public class ${table.controllerName} {

    @Autowired
    private ${table.serviceName} ${lowerServiceName};

    /**
     * 查询列表
     * @param ${lowerEntityName}
     * @param baseEntity
     * @return
     */
    @PostMapping("/list")
    public DataResult list(@RequestBody ${entity} ${lowerEntityName}, BaseEntity baseEntity) {
        return DataResult.success(${lowerServiceName}.getPageList(${lowerEntityName}, baseEntity));
    }

    /**
     * 新增数据
     * @param ${lowerEntityName}
     * @return
     */
    @PostMapping("/add")
    public DataResult add(@RequestBody ${entity} ${lowerEntityName}) {
        ${lowerServiceName}.add(${lowerEntityName});
        return DataResult.success();
    }

    /**
     * 修改数据
     * @param ${lowerEntityName}
     * @return
     */
    @PutMapping("/edit")
    public DataResult edit(@RequestBody ${entity} ${lowerEntityName}) {
        ${lowerServiceName}.edit(${lowerEntityName});
        return DataResult.success();
    }

    /**
     * 查看详情
     * @param ${keyPropertyName}
     * @return
     */
    @GetMapping("/detail/{${keyPropertyName}}")
    public DataResult detail(@PathVariable ${keyPropertyType} ${keyPropertyName}) {
        ${entity} ${lowerEntityName} = ${lowerServiceName}.detail(${keyPropertyName});
        return DataResult.success(${lowerEntityName});
    }

    /**
     * 删除数据
     * @param ids
     * @return
     */
    @DeleteMapping("/delete/{ids}")
    public DataResult delete(@PathVariable List<String> ids) {
        ${lowerServiceName}.delete(ids);
        return DataResult.success();
    }

}
